package com.lottery.ruok.lottrey.ui

import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
import com.lottery.ruok.lottrey.R
import com.lottery.ruok.lottrey.activity.BaseActivity

class BottomButtonModule(baseActivity: BaseActivity,
                         private val confirmAction: ()->Unit,
                         val changeMoneyForEach: (String)->Unit,
                         private val resetAction: ()->Unit){
    val collapse_confirm: View = baseActivity.findViewById(R.id.collapse_confirm)
    val extend_confirm: View
    val collapse_layout: View
    val extend_layout: View
    val reset: View
    val edit_area: View
    val quick_money: EditText

    init {
        extend_confirm = baseActivity.findViewById(R.id.extend_confirm)
        collapse_layout = baseActivity.findViewById(R.id.collapse_layout)
        extend_layout = baseActivity.findViewById(R.id.extend_layout)
        reset = baseActivity.findViewById(R.id.reset)
        edit_area = baseActivity.findViewById(R.id.edit_area)
        quick_money = baseActivity.findViewById(R.id.quick_money)

        collapse_confirm.setOnClickListener {
            confirmAction.invoke()
        }
        extend_confirm.setOnClickListener {
            confirmAction.invoke()
        }
        collapse_layout.setOnClickListener {
            collapse_layout.visibility = View.GONE
            extend_layout.visibility = View.VISIBLE
        }
        extend_layout.setOnClickListener {
            collapse_layout.visibility = View.VISIBLE
            extend_layout.visibility = View.GONE
        }
        reset.setOnClickListener {
            resetAction.invoke()
        }
        edit_area.setOnClickListener {

        }
        quick_money.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(p0: Editable?) {//如果是空白的话，那么就相当于是0
                var result = p0.toString()
                if(p0?.length == 0){
                    result = "0"
                }
                changeMoneyForEach.invoke(result)
            }

            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }
        })
    }
}